package com.sygj.nacos.consumer.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.net.URI;

@RestController
public class DemoController {
    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private  LoadBalancerClient loadBalancerClient;
    @GetMapping("/test")
    private String test(){
        ServiceInstance choose = loadBalancerClient.choose("service-provider");
        URI uri = choose.getUri();
        return restTemplate.getForObject(uri+"/demo",String.class);
    };
}
